<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/home/include/init_home.jsp" %>
<%@ page import="com.qbooks.board.*" %>
<%
	String board_id			= StringUtil.nvl(request.getParameter("board_id"));
	String search_col		= StringUtil.nvl(request.getParameter("search_col"), "subject");
	String search_word		= StringUtil.nvl(request.getParameter("search_word"));
	String curr_page 		= StringUtil.nvl(request.getParameter("curr_page"), "1");

	String search_url		= "./wordList.jsp?board_id="+board_id+"&search_col="+search_col+"&search_word="+search_word;

	BoardDAO boardDAO 		= new BoardDAO();
	
	HashMap infos = new HashMap();
	infos.put("board_id",		board_id);
	
	HashList boardInfo		= boardDAO.selectBoardInfo(infos);

	infos.put("search_col",		search_col);
	infos.put("search_word",	search_word);
	infos.put("curr_page",		curr_page);
	infos.put("line_per_page",	boardInfo.get("line_per_page",0));
	
	HashList wordList 		= boardDAO.selectWordList(infos);
	
	//쓰기권한
	boolean bWritable		= true;
	if ("A".equals(boardInfo.get("write_auth",0))) {	//관리자
		bWritable = isAdmin;
	} else if ("M".equals(boardInfo.get("write_auth",0))) {	//회원
		bWritable = isLogin;
	}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title><%= HOME_NAME %></title>
	<%@ include file="/cms/include/cssnjs.jsp"  %>
	<script type="text/javascript">
	$(document).ready(function() {

	});
	</script>
</head>
<body>
	<div id="wrap">
		<h3><%= boardInfo.get("board_name",0) %></h3>

        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table_03">
        <colgroup>
					<col width="100px"/>
					<col />
					<col width="60px"/>
					<col width="60px"/>
					<col width="60px"/>
				</colgroup>
				<thead>
                    <tr>
	                    <th><p>No</p></th>
	                    <th><p>제목</p></th>
	                    <th><p>작성자</p></th>
	                    <th><p>조회수</p></th>
	                    <th><p>작성일</p></th>
	                </tr>
	            </thead>
	            <tbody>
       <%
         String prevWordNum = "";
         for (int i = 0; i < wordList.size(); i++) {

       %>
                      <tr>
                        <td  align="center" valign="middle">
                        <%			if (prevWordNum.equals(wordList.get("word_num",i))) {	%>
										&nbsp;
						<%			} else {	%>
										<%= wordList.get("word_num",i) %>
						<%			}	%>
                        </td>
                        <td valign="middle" class="board_txt">
		<%			if (wordList.getInt("depth",i)> 0)
				 	{
		%>			 		<span style="padding-left:<%= 10 * (wordList.getInt("depth",i)-1) %>px">&nbsp;</span>
							<img src="/img/icon/ico_re_i.gif"/>
		<%			}	%>
                        <a href="./wordView.jsp?word_id=<%=wordList.get("word_id",i) %>&board_id=<%=board_id %>&search_col=<%=search_col%>&search_word=<%=search_word%>&curr_page=<%=curr_page%>"><%= StringUtil.substring(wordList.get("subject",i),34) %></a></td>
                        <td width="100" align="center" valign="middle"><%= wordList.get("author_name",i) %></td>
                        <td width="100" align="center" valign="middle"><%= wordList.get("count",i) %></td>
                        <td width="100" align="center" valign="middle"><%= wordList.get("init_date",i) %></td>
                      </tr>
   <%
       	prevWordNum = wordList.get("word_num",i);
         } %>
         				</tbody>
                    </table>


<%	if (bWritable) {	%>
    	<div style="text-align:right">
			<a href="./wordWrite.jsp?board_id=<%= board_id %>">글쓰기</a>
		</div>
<%	}	%>

		<!-- 검색조건 -->
        <div style="text-align:center">
           	<form name="searchForm" method="post" action="./wordList.jsp">
        		<input type="hidden" name="board_id" value="<%= board_id %>"/>
	            <select name="search_col" style="width:80px;">
	              <option value="subject" <%= StringUtil.selected("subject", search_col) %>>제목</option>
	              <option value="content" <%= StringUtil.selected("content", search_word) %>>내용</option>
	              <option value="author_name" <%= StringUtil.selected("author_name", search_word) %>>글쓴이</option>
	            </select>
				<input type="text" name="search_word" size="5" style="width:160px;" value="<%= search_word %>" />
				<input type="image" value="찾기" />
			</form>
        </div>

		<div class="pageNavi">
			<%= boardDAO.getPageHtml(infos, search_url) %>
		</div>

</div>
</body>
</html>
